// components/common/record-item/index.js
const componentBehavior = require('../../../behaviors/component');
const { COMPONENT_OPTIONS } = require('../../../constants/common');
const { formatDate } = require('../../../common/utils');

Component({
    behaviors: [componentBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        keyId: {
            type: String,
            value: '',
        },
        name: {
            type: String,
            value: '',
        },
        type: {
            type: String,
            value: 'add', // 取值：add、minus
        },
        value: {
            type: String,
            value: '',
            observer: function (val, oldVal) {
                this.setData({
                    _value: Math.abs(val),
                });
            }
        },
        unit: {
            type: String,
            value: '￥',
        },
        date: {
            type: Date,
            value: '',
            observer: function (val, oldVal) {
                this.setData({
                    dateString: formatDate(val, 'YYYY.MM.DD HH:mm'),
                });
            },
        },
        tag: {
            type: String,
            value: '',
        },
    },
    data: {
        dateString: '',
        _value: 0,
    },
    methods: {
        handleClick(e) {
            this.triggerEvent('click', this.data.keyId);
        },
    }
})
